﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using SoftSource.Common;
using SoftSource.MVVMC;
using SoftSource.Timecard.ViewModelInterfaces;

namespace SoftSource.Timecard.Views
{
    public sealed partial class MainView : UserControl, IView<IMainViewModelConsume>
    {
        public MainView()
        {
            InitializeComponent();

            Loaded += MainView_Loaded;
        }

        #region Events

        void MainView_Loaded(object sender, RoutedEventArgs e)
        {
            InitializeSummary();
            InitializeManagement();
            IntializeEntriesList();
            IntializeReportList();
        }

        #endregion Events

        #region Methods

        private void InitializeSummary()
        {
            if (this.ViewModel.CreateSummaryView == null)
            {
                this.manageTab.IsSelected = true;
            }
            else
            {
                UIElement summary = this.ViewModel.CreateSummaryView.TryInvoke();

                this.SummaryContent.Child = null;
                this.SummaryContent.Child = summary;
            }
        }

        private void InitializeManagement()
        {
            if (this.ViewModel.CreateManagementView == null)
            {
                this.entriesTab.IsSelected = true;
            }
            else
            {
                UIElement management = this.ViewModel.CreateManagementView.TryInvoke();

                this.ManagementContent.Child = null;
                this.ManagementContent.Child = management;
            }
        }

        private void IntializeEntriesList()
        {
            if (this.ViewModel.CreateTimeEntryListView == null)
            {
                this.reportsTab.IsSelected = true;
            }
            else
            {
                UIElement entriesList = this.ViewModel.CreateTimeEntryListView.TryInvoke();

                this.EntriesContent.Child = null;
                this.EntriesContent.Child = entriesList;
            }
        }

        private void IntializeReportList()
        {
            UIElement reportList = this.ViewModel.CreateReportListView.TryInvoke();

            this.ReportsContent.Child = null;
            this.ReportsContent.Child = reportList;
        }

        #endregion Methods

        #region IView<IMainViewModel> Members

        public IMainViewModelConsume ViewModel
        {
            get { return this.DataContext as IMainViewModel; }
            set { this.DataContext = value; }
        }

        #endregion

        #region INavigatable Members

        public void Navigate(Queue<string> navigationQueue)
        {
            throw new System.NotImplementedException();
        }

        public IObservable<Queue<string>> Navigated { get; private set; }

        #endregion
    }
}
